package ex3.board;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import ex3.reversi.ReversiGame;

public class GameBoard extends JFrame implements ActionListener{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JPanel _mainPanel, _gamePanel, _gameActionsPanel;
	private Container contentPane;
	
	private JButton _startNewGameButton;
	private JButton _exitGameButton;
		
	public GameBoard(String s, int gameMode, int startingPlayer)
	{
		super(s);
		
		this._exitGameButton = new JButton("Exit");
		this._startNewGameButton = new JButton ("New Game");
		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.contentPane = getContentPane();
		setLayout(new BorderLayout());
		this._mainPanel = new JPanel();
	
		this._gamePanel = new GamePanel(gameMode, startingPlayer, this);
		
		this._gameActionsPanel = new GameActionsPanel(this._startNewGameButton, this._exitGameButton);	
		this._mainPanel.setLayout(null);
		this.contentPane.add(this._mainPanel);
		this._mainPanel.add(_gamePanel).setBounds(0,0,600,600);
		this._mainPanel.add(this._gameActionsPanel).setBounds(0,600,800,600);
		this._gameActionsPanel.setBackground(Color.LIGHT_GRAY);
		
		this._exitGameButton.addActionListener(this);
		this._startNewGameButton.addActionListener(this);

		this.setResizable(false);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		
		
		if (e.getSource().equals(this._exitGameButton))
			System.exit(0);
		
		if (e.getSource().equals(this._startNewGameButton)){
			
			this.dispose();
			new ReversiGame();
		}
		
	}
} 
